Hi,
How to customize tables in SwiftUI its color background for example, the background modifier doesn't work ? how to change separator lines ? rows background colors ? give header row different colors to its text and background color ?
Kind Regards
Post
Replies
Boosts
Views
Activity
Hi,
Is it possible to manually create collapsable areas in Xcode when it doesn't show automatically , for example variables definition area in views ?
Kind Regards
Hi,
Im developing a data centric App using SwiftData, I noticed that the device I use for testing doesn't sync its data with the simulator although both have same Apple Account ? What's Im missing here ? arched is my project settings.
Kind Regards
I want to create master details relationship between patient and vitals signs so which of option codes below are better performance wise ? Option one is master - details done manually ..
option 1
@Model
class TestResult {
@Attribute(.primaryKey) var id: UUID
var patientID: UUID
Option 2
@Model
final class Vital {
var patient: Patient?
Hi,
The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error ."Cannot assign through subscript: 'self' is immutable" how to solve this issue ?
Kind Regards
struct ListSel<T: PersistentModel>: View {
@Bindable var dataModule: T
@Binding var txtValue: String
var keyPath: WritableKeyPath<T, String>
var turncate: CGFloat? = 94.0
var image = ""
var body: some View {
HStack {
Text(txtValue)
.foregroundColor(sysSecondary)
.font(.subheadline)
.onChange(of: txtValue) { value in
dataModule[keyPath: keyPath] = value
}
Image(systemName: image)
.foregroundColor(sysSecondary)
.font(.subheadline)
.imageScale(.small)
.symbolRenderingMode(.hierarchical)
.scaleEffect(0.8)
}
.frame(width: turncate, height: 20, alignment: .leading)
.truncationMode(.tail)
}
}
Hi, I have the view below that I want it to get any sort of SwiftData model and display and string property of that module, but I get the error mentioned below as well, also the preview have an error as below, how to fix it ? I know its little complicated.
Error for the view GWidget
" 'init(wrappedValue:)' is unavailable: The wrapped value must be an object that conforms to Observable "
Error of preview
" Cannot use explicit 'return' statement in the body of result builder 'ViewBuilder' "
3, Code
#Preview {
do {
let configuration = ModelConfiguration(isStoredInMemoryOnly: true)
let container = try ModelContainer(for: Patient.self, configurations: configuration)
let example = Patient(firstName: "Ammar S. Mitoori", mobileNumber: "+974 5515 7818", homePhone: "+974 5515 7818", email: "ammar.s.mitoori@gmail.com", bloodType: "O+")
// Pass the model (Patient) and the keyPath to the bloodType property
return GWidget(model: example, keyPath: \Patient.bloodType)
.modelContainer(container)
} catch {
fatalError("Fatal Error")
}
}
4. Code for the Gwidget View
```import SwiftUI
import SwiftData
struct GWidget<T>: View {
@Bindable var model: T
var keyPath: KeyPath<T, String> // Key path to any string property
// Variables for the modified string and the last character
var bloodTypeWithoutLast: String {
let bloodType = model[keyPath: keyPath]
return String(bloodType.dropLast())
}
var lastCharacter: String {
let bloodType = model[keyPath: keyPath]
return String(bloodType.suffix(1))
}
var body: some View {
VStack(alignment: .leading) {
Text("Blood Type")
.font(.footnote)
.foregroundStyle(sysPrimery07)
HStack (alignment: .lastTextBaseline) {
Text(bloodTypeWithoutLast)
.fontWeight(.bold)
.font(.title2)
.foregroundStyle(sysPrimery07)
VStack(alignment: .leading, spacing: -5) {
Text(lastCharacter)
.fontWeight(.bold)
Text(lastCharacter == "+" ? "Positive" : "Negative")
}
.font(.caption2)
.foregroundStyle(lastCharacter == "+" ? .green : .pink)
}
}
}
}
Hi
When connecting a SwiftData module property to a SwiftUI view such as a text field and the field changes by user the property get updated in the SwiftData database, now suppose I want to run a validation code or delay updates to Database till use click a submit button how to do that ? delay those auto updates if we can name it ?
Kind Regards
Code Example
import SwiftUI
import SwiftData
struct GListSel2: View {
@Bindable var patient: Patient
var body: some View {
HStack {
TextField("Gender", text: $patient.gender)
}
}
}
Hi,
When passing a SwftData Module to a view that receives it in a @Binadable property variable I get an error that it doesn't conform to Observation, I don't know how to solve this issue, even adding @Observable type to the generic in the structure definition won't solve it, any suggestions ?
Kind Regards
Hi,
In this year WWDC 2024 conference a new update to SwiftData allows it to connect to other kind of data sources or databases, at ;east this is what I understood, since then didn't see any tutorial or help document on how to do that for example connecting SwiftData to Firebase if possible ?
Kind Regards
Hi,
Im trying to use ForEach without list to get rid of the navigation chevron , but the sipe to delete modifier stop working, is there a some solution ?
Kind Regards
Button(role: .destructive) {
deletePatient(patient: patient)
} label: {
VStack {
Label("Delete", systemImage: "trash")
Image(systemName: "Trash")
}
}
}
Hi,
If Im in detailsOnly mode in SplitView how to manually open the SideBar as popover same as behavior as default rectangle menu icon at top of Details View.
Kind Regards
Hi,
Os to possible to customize the icon, color, positioning of the SplitView ToolBar that shows at details view, the menu blue icon. add buttons to it ? change its color, icon, size ? position like adding paddings ?
Kind Regards
Hi,
When SplitView is in detailsOnly and I swipe from left side the sidebar appears as popover above the details content, but when I try to open it manually by settings the columnVisibility to doubleColumn it pushes the details view and shows, so haw to make it appear as poorer ?
Kind Regards
Hi,
The new TabBar, SideBar combination is very nice, but I tried customizing like text sizes, icon sizes using imageScale and all dint have any effect, also shows of selected item in side bar couldn't customize it, is there any suggestions ?
Kind Regards
Hi,
However I tried to reduce space between list rows in below code I fail, is there any way to reduce this space ?
@State var flag: Bool = false
var myList: [String] = ["Hello", "World", "SwiftUI"]
var body: some View {
VStack(alignment: .leading) {
List (myList, id: \.self) { list in
Text(list)
.border(Color.black)
.font(.system(size: 12)) // Smaller font size
.frame(maxWidth: .infinity, minHeight: 20, alignment: .leading) // Reduced height
.padding(.vertical, 4) // Minimal padding for vertical spacing
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) // Remove insets
.listRowSeparator(.hidden) // Hide separator
}
.listStyle(.plain)
}
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(sysSecondary.opacity(0.4), lineWidth: 1)
)
.frame(width: 220, height:260)
.background(.white)
.clipShape (RoundedRectangle (cornerRadius: 10))
}
}